package gateway.controller;

import common.controller.base.BaseController;
import common.model.response.base.Result;
import common.service.CommonSysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 前端控制器
 *
 * @author 米泽鹏
 * @since 2022-02-26
 */
@Api(tags = "gateway测试ShardingSphere")
@RestController
@RequestMapping("/gateway/test-sharding")
public class GatewayTestShardingController extends BaseController {

	@Resource
	private CommonSysUserService userService;
	@Resource
	private SqlSessionTemplate sqlSessionTemplate;

	@ApiOperation(value = "测试select", notes = "测试select")
	@PostMapping("/select")
//	@DS(DataSourceConstants.MYSQL_DATASOURCE)
//	@DS(DataSourceConstants.SHARDING_DATASOURCE)
	public Result<?> select() {

		// 手动切换数据源
//		DynamicDataSourceContextHolder.push(DataSourceConstants.MYSQL_DATASOURCE);
//		DynamicDataSourceContextHolder.push(DataSourceConstants.SHARDING_DATASOURCE);

		// 测试Service
//		return successWithData(commonTestShardingService.list());

		// 测试Mapper
//		return successWithData(testShardingMapper.selectList(null));

		// 测试写在xml中的sql
//		return successWithData(testShardingMapper.getAllTestSharding());

		// 测试SqlSessionTemplate
		return successWithData(sqlSessionTemplate.selectList("common.mapper.CommonSysLogMapper.getAllByMethodName", "testBaseSeataTransaction"));

		// 测试非分片表
//		return successWithData(userService.list());

	}

}
